<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>ERP管理系统</title>
    <th:block th:include="include::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">


            <div class="layui-form-item">
                <label for="roleName" class="layui-form-label">
                    <span class="x-red">*</span>角色名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="roleName" name="roleName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="roleLockout" class="layui-form-label">
                    状态
                </label>
                <div class="layui-input-inline">
                    <select type="" id="roleLockout" name="roleLockout" required="" lay-verify="required"
                            autocomplete="off" class="layui-input">
                        <option></option>
                        <option value="1">有效角色</option>
                        <option value="0">锁定</option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item" th:each="item:${submenus}" th:if="${item.powerCount!=0&&item.powerCount!=null}">
                <label class="layui-form-label">[[${item.name}]]:</label>
                <div class="layui-input-block">
                    <th:block th:each="item1:${powers}" th:if="${item1.parent==item.name}">
                        <input th:ids="${item1.powerId}" type="checkbox" th:name="${item1.type}" th:title="${item1.name}">
                    </th:block>

                </div>
            </div>

            <div class="layui-form-item">
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script >layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        $(".select").css("width","190px");


        //监听提交
        form.on('submit(add)',
            function(data) {
                var inputs=$("input[type='checkbox']");
                var ins=[];
                for (var i=0;i<inputs.length;i++) {
                    if(inputs[i].checked==true){
                        ins.push(inputs[i].getAttribute("ids"))
                    }
                }
                var ids=JSON.stringify(ins);
                $.post("/role/add",{
                    "ids":ids,
                    "roleName":data.field.roleName,
                    "roleLockout":data.field.roleLockout
                },function(res){
                    if(res.success){
                        layer.alert(res.msg, {
                                icon: 6
                            },
                            function() {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });

                    }else{
                        layer.alert(res.msg, {icon:5});
                        return;
                    }
                });
                return false;
            });

    });</script>
</body>

</html>
